package com.duofan.gmall.ware.service;

import com.baomidou.mybatisplus.extension.service.IService;
import com.duofan.gmall.common.exception.NoStockException;
import com.duofan.gmall.common.to.SkuHasStockTo;
import com.duofan.gmall.common.to.mq.OrderTo;
import com.duofan.gmall.common.to.mq.StockLockedTo;
import com.duofan.gmall.common.utils.PageUtils;
import com.duofan.gmall.ware.entity.WareSkuEntity;
import com.duofan.gmall.ware.vo.WareSkuLockVo;

import java.io.IOException;
import java.util.List;
import java.util.Map;

/**
 * 商品库存
 *
 * @author Vincent
 * @email wu_peizhen@126.com
 * @date 2023-05-07 22:06:39
 */
public interface WareSkuService extends IService<WareSkuEntity> {

    PageUtils queryPage(Map<String, Object> params);

    void addStock(Long skuId, Long wareId, Integer skuNum);

    List<SkuHasStockTo> getSkusHasStock(List<Long> skuIds);

    /**
     * 为某个订单锁定库存
     * @param vo
     * @return
     */
    void orderLockStock(WareSkuLockVo vo) throws NoStockException;

    /**
     * 解锁库存
     * @param to
     * @return
     * @throws IOException
     */
    void unlockStock(StockLockedTo to) throws IOException;

    void unlockStock(OrderTo orderTo);

}

